import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Search from '@/views/Search'
import SearchResultList from '@/views/Search/ResultList'

import ArticleDetail from '@/views/Article/id'

import Home from '@/views/Layout/Home'
import User from '@/views/Layout/User'

Vue.use(VueRouter)

const routes = [
  {
    // 根路径 的 重定向
    path: '/',
    redirect: '/layout'// 重定向
  }, {
    // 登录页
    path: '/login',
    component: Login
  }, {
    // 首页
    path: '/layout',
    component: Layout,
    redirect: '/layout/home',
    children: [
      {
        // path: '', 或者 重定向
        path: 'home',
        component: Home
      }, {
        path: 'user',
        component: User
      }
    ]
  }, {
    // 搜索页
    path: '/search',
    component: Search
  }, {
    // 搜索页结果页
    path: '/search/:keyword', // 动态路由
    name: 'resultlist',
    component: SearchResultList
  }, {
    // 文章详情页
    path: '/article',
    component: ArticleDetail
  }
]

const router = new VueRouter({
  routes
})

export default router
